﻿using Knowledge.EF.Back.Auth;
using Knowledge.EF.Back.Models;
using Knowledge.EF.Back.Models.Users;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace Knowledge.EF.Back.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UsersController : ControllerBase
    {
        private readonly IMediator _mediator;
        public UsersController(IMediator m)
        {
            _mediator = m;
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="ul"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseResult> Login(UserLogin ul)
        {
            var result = await _mediator.Send(ul);
            return result;
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseResult> Register(UserRegister ur)
        {
            var result = await _mediator.Send(ur);
            return result;
        }
        /// <summary>
        ///  查询
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Author]
        public async Task<BaseResult> ListUsers()
        {
            var result = await _mediator.Send(new UserList());
            return result;
        }
    }
}
